package data.type.and.operator;

import general.DataTypeNOperator;

public class DtoOperator implements DataTypeNOperator{

	private void arithmeticOperator() {
		System.out.println("\n \nArithmetic Operator");
		System.out.println("--------------------");
		int a = 1;
		int s = 10;
		System.out.println("So a: " + a);
		System.out.println("So b: " + s);
		System.out.println("a - b: " + (a - s));
		System.out.println("a + b: " + (a + s));
		System.out.println("a * b: " + (a * s));
		System.out.println("a / b: " + (s == 0 ? "khong chia duoc" : a / s));
		System.out.println("a % b: " + (a % s));
		System.out.println("++a: " + ++a);
		System.out.println("a : " + a);
		System.out.println("b--: " + s--);
		System.out.println("b: " + s);

		byte b = 5;
		int i = 3;
		double d = b / i;
		System.out.println(d);
	}

	private void instanceOperator(Object obj) {
		if (obj instanceof String) {
			System.out.println("String");
		}

		else if (obj instanceof Integer) {
			System.out.println("Integer");
		} else
			System.out.println("Khong la gi ca");
	}

	private void equalObjPri() {
		System.out.println("\n \nEqual Operator");
		System.out.println("--------------------");
		String a = "asd";
		String b;
		b = new String("asd");
		String c = "asd";
		System.out.println("Gia tri a: " + a);
		System.out.println("Gia tri a: " + b);
		if (a != c) {
			System.out.println("a != b");
		}
		if (a.equals(b)) {
			System.out.println("a equals b");
		}
	}
	
	private void compareOperator()
	{
		int i = 0;
		int j = 10;
		if ((i == 1) & (j-- == 9)) {
			System.out.println("&: " + i + "; " + j);
		}
		System.out.println("&: " + j);
		
		if ((i == 1) && (j-- == 9)) {
			System.out.println("&&: " + i + "; " + j);
		}
		System.out.println("&&: " + j);
		
		if (i == 0 | j-- == 9) {
			System.out.println("|: " + i + "; " + j);
		}
		System.out.println("|: " + j);
		
		if (i == 0 || j-- == 9) {
			System.out.println("||: " + i + "; " + j);
		}
		System.out.println("||: " + j);
		
		
	}
	public static void main(String[] args) {
		
	}

	@Override
	public void run() {
		DtoOperator ope = new DtoOperator();
		ope.arithmeticOperator();
		System.out.println("\n \nInstance Operator");
		System.out.println("--------------------");
		ope.instanceOperator("");
		ope.instanceOperator(true);
		ope.equalObjPri();
		ope.compareOperator();
	}
}
